import 'package:flutter/material.dart';

import '../../riki_ui_demo.dart';

/// 打扮家App规范汇总页

class StandardsPage extends StatefulWidget {
  const StandardsPage({Key? key}) : super(key: key);

  @override
  _StandardsPageState createState() => _StandardsPageState();
}

class _StandardsPageState extends State<StandardsPage> with AutomaticKeepAliveClientMixin {
  List<_RikiUIKitDemoListData> get _demoList => RikiUiKitApp.standardsRoutes.keys
      .map((String key) => _RikiUIKitDemoListData(title: key.substring(1, key.length), targetRouteName: key))
      .toList();

  List<Widget> get _demoCards {
    final List<Widget> list = <Widget>[];
    for (_RikiUIKitDemoListData demoData in _demoList) {
      final Widget card = Card(
        clipBehavior: Clip.antiAlias,
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(5)),
        ),
        elevation: 1,
        child: InkWell(
          onTap: () {
            print("targetRouteName = ${demoData.targetRouteName}");
            Navigator.pushNamed(context, demoData.targetRouteName);
          },
          splashColor: Theme.of(context).colorScheme.onSurface.withOpacity(0.12),
          highlightColor: Colors.transparent,
          child: Center(
            child: Text(
              demoData.title,
              style: const TextStyle(fontSize: 15),
            ),
          ),
        ),
      );
      list.add(card);
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        color: const Color(0xFFFCFCFC),
        child: GridView(
          padding: const EdgeInsets.symmetric(vertical: 20),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: 9 / 4,
            mainAxisSpacing: 20,
            crossAxisSpacing: 20,
          ),
          children: _demoCards,
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}

class _RikiUIKitDemoListData {
  const _RikiUIKitDemoListData({
    required this.title,
    required this.targetRouteName,
  });

  final String title;
  final String targetRouteName;
}
